package com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use;

import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.Address;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.Payment;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.User;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.AddressRequest;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.PaymentRequest;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.UserRequest;

public class Client {
    public static void main(String[] args) {
        // 创建责任链
        Handler userHandler = new UserHandler();
        Handler paymentHandler = new PaymentHandler();
        Handler addressHandler = new AddressHandler();
        userHandler.setSuccessor(paymentHandler);
        paymentHandler.setSuccessor(addressHandler);

        // 创建请求并发送给责任链
        User user = new User(true);
        Payment payment = new Payment(true);
        Address address = new Address(true);

        // 发送用户请求
        userHandler.handleRequest(new UserRequest(user));

        // 发送支付请求
        userHandler.handleRequest(new PaymentRequest(payment));

        // 发送地址请求
        userHandler.handleRequest(new AddressRequest(address));

        // 尝试使用无效用户发送请求
        User invalidUser = new User(false);
        userHandler.handleRequest(new UserRequest(invalidUser));
    }
}
